package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.TeachplanDTO;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;

import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    @Override
    @GetMapping("/courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryCourseTeacherList(@PathVariable Long courseBaseId) {
        Long companyId = UAASecurityUtil.getCompanyId();
        return courseTeacherService.getCourseTeacherByCourseId(courseBaseId,companyId);
    }

    @Override
    @PostMapping("/courseTeacher")
    public CourseTeacherDTO createOrModifyCourseTeacher(@RequestBody CourseTeacherVO vo) {

        CourseTeacherDTO dto = CourseTeacherConvert.INSTANCE.vo2dtoTo(vo);
        Long companyId = UAASecurityUtil.getCompanyId();
        return  courseTeacherService.createOrModifyCourseTeachr(dto,companyId);

    }

    @Override
    @DeleteMapping("/courseTeacher/course/{courseId}/{courseTeacherId}")
    public Boolean removeCourseTeacher(@PathVariable Long courseId, @PathVariable Long courseTeacherId) {
        Long companyId = UAASecurityUtil.getCompanyId();
        return  courseTeacherService.removeCourseTeachr(courseId,courseTeacherId,companyId);
    }
    //courseTeacher/course/22/1
}
